package leetcode_day._2021._202109._0110;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/9/6 8:58
 * 二分查找
 * 算法：二分查找
 */
public class _06_704 {

    public int search(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] == target) return mid;
            if (nums[mid] > target) r = mid - 1;
            else l = mid + 1;
        }
        return -1;
    }

}
